#include <iostream>
#include <vector>
#include <string>
#include <queue>
using namespace std;
int bfs(vector<string>& g, int sx, int sy, int dx, int dy)
{
    queue<pair<int, int>> q;
    q.emplace(sx, sy);
    int step = 0;
    vector<vector<int>> dir{ {-1, 0}, {0, -1}, {0, 1}, {1, 0} };
    while (!q.empty())
    {
        size_t sz = q.size();
        ++step;
        for (int i = 0; i < sz; ++i)
        {
            auto front = q.front();
            q.pop();
            for (int j = 0; j < dir.size(); ++j)
            {
                int x = front.first + dir[j][0];
                int y = front.second + dir[j][1];
                if (x == dx && y == dy)
                    return step;
                if (x < 0 || x >= g.size() || y < 0 || y >= g[0].size() || g[x][y] != '.')
                    continue;
                g[x][y] = '#'; //visited
                q.emplace(x, y);
            }
        }
    }
    return -1;
}
int main() 
{
    vector<string> board(10);
    while (cin >> board[0])
    {
        for (int i = 1; i < 10; ++i)
            cin >> board[i];
        cout << bfs(board, 0, 1, 9, 8) << endl;
    }
    return 0;
}